/*
 * ArrayListModel.java  0.4.0 / Oct 24, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
package com.cute4j.swing.list;

import com.cute4j.util.CommonConstants;

/**
 * Array List Model.
 *
 * @author Slobodan Vrkacevic
 * @version 0.4.0
 */
public class ArrayListModel extends AbstractListModel {

// Private Fields. -------------------------------------------------------------

  private final Object[] array;

// Public Constructors. --------------------------------------------------------

  /**
   * Constructs new ArrayListModel object.
   *
   * @param array the array model
   */
  public ArrayListModel(Object[] array) {
    if (array == null) {
      this.array = CommonConstants.EMPTY_OBJECT_ARRAY;
    } else {
      this.array = (Object[])array.clone();
    }
  }

// Overridden Methods. ---------------------------------------------------------

  /**
   * {@inheritDoc}
   */
  public Object getElementAt(int index) {
    return array[index];
  }

  /**
   * {@inheritDoc}
   */
  public int getSize() {
    return array.length;
  }

}
